<template>
	<view class="con">
		<view class="con__top">
			<view class="">
				Hello!
			</view>
			<view class="" style="font-size: 46rpx;">
				请绑定您的手机号
			</view>
			<image src="/static/loginbg.png" class="con__top__bg" mode=""></image>
		</view>
		<view class="con__box">
			<input class="con__box__inp" placeholder="请输入手机号" v-model="form.mobile" />
			<view class="" style="position: relative;">
				<input class="con__box__inp" placeholder="请输入验证码" v-model="form.code" />
				<u-button :customStyle="{
					position:'absolute',
					width:'fit-content',
					height:'57.25rpx',
					top:'24rpx',
					right:'24rpx',
					fontSize:'23rpx',
				}" @tap="getCode" color="#6492FF" shape='circle'>{{tips}}</u-button>
			</view>
			<view class="">
				<u-button :customStyle="{
					height:'80.15rpx',
					fontSize:'30rpx',
					color:'#00649A',
					fontWeight:'bold'
				}" color="#98d5ff" shape='circle' @click="login" :loading="loading" text="绑定"></u-button>

			</view>

		</view>
		<u-code :seconds="seconds" @end="end" @start="start" ref="uCode" @change="codeChange"></u-code>
	</view>
</template>

<script>
	import user from '@/api/_user.js'
	export default {
		data() {
			return {
				tips: '',
				// refCode: null,
				seconds: 10,
				checked: false,
				form: {
					"mobile": "",
					"code": "1234"
				},
				loading:false
			};
		},
		methods: {
			codeChange(text) {
				this.tips = text;
			},
			getCode() {
				if (this.$refs.uCode.canGetCode) {
					// 模拟向后端请求验证码
					uni.showLoading({
						title: '正在获取验证码'
					})
					setTimeout(() => {
						uni.hideLoading();
						// 这里此提示会被this.start()方法中的提示覆盖
						uni.$u.toast('验证码已发送');
						// 通知验证码组件内部开始倒计时
						this.$refs.uCode.start();
					}, 2000);
				} else {
					uni.$u.toast('倒计时结束后再发送');
				}
			},
			end() {
				uni.$u.toast('倒计时结束');
			},
			start() {
				uni.$u.toast('倒计时开始');
			},

			async login() {
				let {mobile,code} = this.form
				if(!mobile){
					uni.$u.toast('请输入手机号')
					return
				}
				if(!code){
					uni.$u.toast('请输入验证码')
					return
				}
				let _this=this
				_this.loading=true
				let res = await user.wx_bind(this.form)
				if(res.data.code==200){
					uni.$u.toast('绑定成功')
					setTimeout(()=>{
						_this.loading=false
						uni.navigateBack()
					},2000)
				}
			},

		}
	}
</script>

<style lang="scss">
	page {
		background: url('https://mp-b54a63ff-3ce2-4df8-8d6e-f855d8976d34.cdn.bspapp.com/img/login.png') 100% no-repeat;
		background-position: top;
		width: 750rpx;
	}

	.con {
		padding: 194rpx 24rpx 0;
		height: calc(100vh - 194rpx);


		&__top {
			font-family: Alimama ShuHeiTi, Alimama ShuHeiTi;
			font-weight: bold;
			font-size: 61rpx;
			color: #000000;
			line-height: 73rpx;
			padding-left: 40rpx;
			margin: 0 0 135rpx;
			position: relative;

			&__bg {
				width: 308.47rpx;
				height: 353.05rpx;
				position: absolute;
				top: -34rpx;
				right: 30.53rpx;
			}
		}

		&__box {
			background: #FFFFFF;
			border-radius: 50rpx 50rpx 0rpx 0rpx;
			padding: 55rpx 50rpx 0;
			height: calc(100% - 194rpx - 135rpx);
			display: flex;
			flex-direction: column;

			&__inp {
				height: 103rpx;
				background: #E8F7FF;
				border-radius: 46rpx;
				padding-left: 54rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 27rpx;
				color: #333;
				line-height: 40rpx;
				font-style: normal;
				text-transform: none;
				margin-bottom: 30rpx;
			}

			&__b {
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				flex: 1;

				&__text {
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 23rpx;
					color: #A19F9F;
					line-height: 40rpx;
					text-align: center;
					font-style: normal;
					text-transform: none;
				}

				&__xy {
					display: flex;
					align-items: center;
					justify-content: center;
					font-family: Alegreya, Alegreya;
					font-weight: 500;
					font-size: 23rpx;
					color: #999999;
					line-height: 40rpx;
					text-align: center;
					font-style: normal;
					text-transform: none;
					padding-bottom: calc(17rpx + env(safe-area-inset-bottom));
				}
			}
		}
	}
</style>